package mahmoud.sigir.search;

import java.util.ArrayList;

import mahmoud.utils.MinHeap;
import mahmoud.utils.Result;
import mahmoud.utils.WieghtedTerm;


public class RocchioQuery 
{
//	private GroundTruthSearcher GTS;
	private static QueryGen QG;
	
	public RocchioQuery(String Location) 
	{
		QG = new QueryGen(Location);
	}

	public MinHeap<Result> search(ArrayList<WieghtedTerm> Q)
	{
		QG.GTS.openSearcher();
		ArrayList<WieghtedTerm> Q2= QG.constructDenseQuery(Q,QueryGen.TrecFile);
		System.out.println(Q2.size());
//		System.out.println(Q2);	
		MinHeap<Result> x = QG.GTS.luceneSearch(Q2);
		QG.GTS.closeSearcher();
		return x; 
	}
	
	public static void main(String[] argc)
	{
		System.out.println("from DQsearcher");
//		RocchioQuery s = new RocchioQuery("D:\\dDocuments\\Code\\builtIndexes\\TREC-FT\\");
		RocchioQuery s = new RocchioQuery("/media/Data/dDocuments/Code/builtIndexes/TREC-FT/");
//		RocchioQuery s = new RocchioQuery("D:\\dDocuments\\Code\\builtIndexes\\OHSUMED\\");
//		s.openSearcher();
		ArrayList<WieghtedTerm> Q = new ArrayList<WieghtedTerm>();
		Q.add(new WieghtedTerm("quantitative", 1));
		Q.add(new WieghtedTerm("algorithmic", 1));
		Q.add(new WieghtedTerm("trading", 1));
		
		s.QG.GTS.openSearcher();
		ArrayList<WieghtedTerm> Q2= s.QG.constructDenseQuery(Q,QueryGen.TrecFile);
		System.out.println(Q2.size());
//		System.out.println(Q2);	
//		System.exit(0);
		
		long start = System.currentTimeMillis();
		MinHeap<Result> x = s.QG.GTS.luceneSearch(Q2);
		long end = System.currentTimeMillis();
//		QG.GTS.closeSearcher();
		System.out.println("Evaluation Took: "+(end-start)/1000.0+" Seconds.");
//		s.closeSearcher();
//		s.constructQuery(Q);
		
	}

}
